#include <TStyle.h>
#include <string>
#include <TH1.h>
#include <TH1F.h>
#include <TH2F.h>
#include <TAxis.h>
#include <TCanvas.h>
#include <TPad.h>
#include <TFile.h>
#include <TLegend.h>

using namespace std;

void q2D1(std::string var, std::string tituloX, std::string tituloY)
{
  Int_t icol=0;
  gStyle->SetFrameBorderMode(icol);
  gStyle->SetFrameFillColor(icol);
  gStyle->SetCanvasBorderMode(icol);
  gStyle->SetCanvasColor(icol);
  gStyle->SetPadBorderMode(icol);
  gStyle->SetPadColor(icol);
  gStyle->SetStatColor(icol);

//  gStyle->SetPaperSize(26,20);
  gStyle->SetPadTopMargin(0.05);
  gStyle->SetPadRightMargin(0.12);
  gStyle->SetPadBottomMargin(0.10);
  gStyle->SetPadLeftMargin(0.10);

  gStyle->SetTitleXOffset(1.3);
  gStyle->SetTitleYOffset(1.3);
  Int_t font=42;
  Double_t tsize=0.05;
  gStyle->SetTextFont(font);
  gStyle->SetTextSize(tsize);
  gStyle->SetLabelFont(font,"x");
  gStyle->SetTitleFont(font,"x");
  gStyle->SetLabelFont(font,"y");
  gStyle->SetTitleFont(font,"y");
  gStyle->SetLabelFont(font,"z");
  gStyle->SetTitleFont(font,"z");
  gStyle->SetLabelSize(tsize,"x");
  gStyle->SetTitleSize(tsize,"x");
  gStyle->SetLabelSize(tsize,"y");
  gStyle->SetTitleSize(tsize,"y");
  gStyle->SetLabelSize(tsize,"z");
  gStyle->SetTitleSize(tsize,"z");
  gStyle->SetMarkerStyle(20);
  gStyle->SetMarkerSize(0.7);
  gStyle->SetHistLineWidth(2);
  gStyle->SetLineStyleString(2,"[12 12]");
  //gStyle->SetEndErrorSize(0.);
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(1111111);
  //gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);
  gStyle->SetPadTickX(1);
  gStyle->SetPadTickY(1);
  gStyle->SetPalette(1);

  TFile *f0,*f1;


  f0 = TFile::Open("../sumbg/plots.root","READ");
  f1 = TFile::Open("../signal/plots.root","READ");
  //f[8] = TFile::Open("../../doplotsalaemma/plots.root","READ");


  TH2F* hsumbg;
  TH2F* hsignal;


  //hreal->Sumw2();
  //hsumbg->Sumw2();
  hsumbg = (TH2F*)f0->Get(var.c_str());
  hsignal = (TH2F*)f1->Get(var.c_str());

 
  std::string tcsumbg = "csumbg"+var;
  std::string tcsignal = "csignal"+var;

  hsumbg->GetXaxis()->SetTitle(tituloX.c_str());
  hsumbg->GetYaxis()->SetTitle(tituloY.c_str());
  hsignal->GetXaxis()->SetTitle(tituloX.c_str());
  hsignal->GetYaxis()->SetTitle(tituloY.c_str());
  hsumbg->SetStats(0);
  hsignal->SetStats(0);


  TCanvas *csumbg = new TCanvas(tcsumbg.c_str(),tcsumbg.c_str());
  csumbg->cd();
  hsumbg->Draw("colz");
  std::string argsumbgpng = "ploticos/"+var+"sumbg.png";
  csumbg->SaveAs(argsumbgpng.c_str());
  csumbg->Close();

  TCanvas *csignal = new TCanvas(tcsignal.c_str(),tcsignal.c_str());
  csignal->cd();
  hsignal->Draw("colz");
  std::string argsignalpng = "ploticos/"+var+"signal.png";
  csignal->SaveAs(argsignalpng.c_str());
  csignal->Close();

}

